package com.linxiao.hrcrm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.linxiao.hrcrm.domain.CrmBlacklist;
import com.linxiao.hrcrm.service.ICrmBlacklistService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户黑名单Controller
 *
 * @author zhoudong
 * @date 2024-03-20
 */
@RestController
@RequestMapping("/hrcrm/blacklist")
public class CrmBlacklistController extends BaseController {
    @Autowired
    private ICrmBlacklistService crmBlacklistService;

    /**
     * 查询客户黑名单列表
     */
    @PreAuthorize("@ss.hasPermi('hrcrm:blacklist:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmBlacklist crmBlacklist) {
        startPage();
        List<CrmBlacklist> list = crmBlacklistService.selectCrmBlacklistList(crmBlacklist);
        return getDataTable(list);
    }

    /**
     * 导出客户黑名单列表
     */
    @PreAuthorize("@ss.hasPermi('hrcrm:blacklist:export')")
    @Log(title = "客户黑名单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CrmBlacklist crmBlacklist) {
        List<CrmBlacklist> list = crmBlacklistService.selectCrmBlacklistList(crmBlacklist);
        ExcelUtil<CrmBlacklist> util = new ExcelUtil<CrmBlacklist>(CrmBlacklist.class);
        util.exportExcel(response, list, "客户黑名单数据");
    }

    /**
     * 获取客户黑名单详细信息
     */
    @PreAuthorize("@ss.hasPermi('hrcrm:blacklist:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(crmBlacklistService.selectCrmBlacklistById(id));
    }

    /**
     * 获取客户黑名单详细信息
     */
    @PreAuthorize("@ss.hasPermi('hrcrm:blacklist:query')")
    @GetMapping(value = "/getInfoByMchIdAndCustomerId")
    public AjaxResult getInfoByMchIdAndCustomerId(CrmBlacklist crmBlacklist) {
        return success(crmBlacklistService.selectCrmBlacklistByMchIdAndCustomerId(crmBlacklist.getMchId(), crmBlacklist.getCustomerId()));
    }

    /**
     * 新增客户黑名单
     */
    @PreAuthorize("@ss.hasPermi('hrcrm:blacklist:add')")
    @Log(title = "客户黑名单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmBlacklist crmBlacklist) {
        return toAjax(crmBlacklistService.insertCrmBlacklist(crmBlacklist));
    }

    /**
     * 修改客户黑名单
     */
    @PreAuthorize("@ss.hasPermi('hrcrm:blacklist:edit')")
    @Log(title = "客户黑名单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmBlacklist crmBlacklist) {
        return toAjax(crmBlacklistService.updateCrmBlacklist(crmBlacklist));
    }

    /**
     * 删除客户黑名单
     */
    @PreAuthorize("@ss.hasPermi('hrcrm:blacklist:remove')")
    @Log(title = "客户黑名单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(crmBlacklistService.deleteCrmBlacklistByIds(ids));
    }
}
